package com.zswlib.netease.webapp.dao;

import com.zswlib.netease.webapp.mapper.BlogMapper;
import com.zswlib.netease.webapp.po.Blog;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by noble on 2018/2/5.
 */
@Repository()
public class BlogDAO {
    @Autowired()
    private SqlSession session;
    @Autowired
    private BlogMapper blogMapper;

    public List<Blog> listBlog(){
        try {
            return blogMapper.listBlog();
        }finally {
            if(session != null){
                session.close();
            }
        }
    }

    @Transactional
    public void saveBlog(Blog blog) throws Exception {
        blogMapper.saveBlog(blog);
        throw new RuntimeException("i am cue");
    }
}
